import React, { useEffect, useState } from 'react'
import { supabase } from '../../../utils'
import './index.scss'
export default function More() {
  // 获取
  const [a,b]=useState()
  const [data,setdata]=useState('')
  async function downloadImage(path) {
    try {
      const { data, error } = await supabase.storage.from('avatars').download(path)
      if (error) {
        throw error
      }
      console.log(data)
      const url = URL.createObjectURL(data)
      console.log(url);
      b(url)
    } catch (error) {
      console.log('Error downloading image: ', error.message)
    }
  }
//   上传图片
async function uploadAvatar(event) {
  try {
    if (!event.target.files || event.target.files.length === 0) {
      throw new Error('You must select an image to upload.')
    }
    const file = event.target.files[0]
    const fileExt = file.name.split('.').pop()
    const fileName = `${Math.random()}.${fileExt}`
    const filePath = `${fileName}`
    let { error: uploadError } = await supabase.storage
      .from('avatars')
      .upload(filePath, file)

    if (uploadError) {
      throw uploadError
    }
    downloadImage(filePath)  //存储完后在获取

  } catch (error) {
    alert(error.message)
  } finally {

  }
}

useEffect(()=>{
  
  
},[])
  return (
    <div>
      
    </div>
  )
}
